<template>
  <div class="mod-config">
    <el-form
      :inline="true"
      :model="dataForm"
      @keyup.enter.native="getDataList()"
    >
      <el-form-item>
        <el-button type="primary" @click="addOrUpdateHandle()">新增</el-button>
        <el-button
          type="danger"
          @click="deleteHandle()"
          :disabled="dataListSelections.length <= 0"
          >批量删除</el-button
        >
      </el-form-item>
    </el-form>
    <el-table
      :data="dataList"
      border
      v-loading="dataListLoading"
      @selection-change="selectionChangeHandle"
      style="width: 100%;"
    >
      <el-table-column
        type="selection"
        header-align="center"
        align="center"
        width="50"
      >
      </el-table-column>
      <el-table-column type="index" width="50"> </el-table-column>
      <el-table-column
        prop="name"
        header-align="center"
        align="center"
        label="名称"
        width="450"
      >
      </el-table-column>
      <el-table-column
        prop="releaseTime"
        header-align="center"
        align="center"
        label="发布时间"
      >
      </el-table-column>
      <el-table-column
        prop="department"
        header-align="center"
        align="center"
        label="发布部门"
      >
      </el-table-column>
      <el-table-column
        prop="paymentTime"
        header-align="center"
        align="center"
        label="发放时间"
      >
      </el-table-column>
      <el-table-column
        prop="person"
        header-align="center"
        align="center"
        label="受益群体"
      >
      </el-table-column>
      <el-table-column
        prop="form"
        header-align="center"
        align="center"
        label="发放形式"
      >
      </el-table-column>
      <el-table-column
        prop="money"
        header-align="center"
        align="center"
        label="金额"
      >
      </el-table-column>
      <el-table-column
        fixed="right"
        header-align="center"
        align="center"
        width="200"
        label="操作"
      >
        <template slot-scope="scope">
          <el-button
            type="text"
            size="small"
            class="button"
            @click="addOrUpdateHandle(scope.row.id)"
            >修改</el-button
          >
          <el-button
            type="text"
            size="small"
            class="button"
            @click="deleteHandle(scope.row.id)"
            >删除</el-button
          >
          <el-button
            type="text"
            size="small"
            class="button"
            @click="checkHandle(scope.row.id)"
            >详情</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageIndex"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper"
    >
    </el-pagination>
    <!-- 弹窗, 新增 / 修改 -->
    <add-or-update
      v-if="addOrUpdateVisible"
      ref="addOrUpdate"
      @refreshDataList="getDataList"
    ></add-or-update>

    <el-dialog
      fullscreen
      title="详情信息"
      :visible.sync="dialogVisible"
      width="95%"
      :before-close="handleClose"
    >
      <div style="width:100%;height:126px" class="head"></div>

      <div class="Article">
         <div class="back-btn">
        <i class="el-icon-back"></i>
        <span>主页</span>
      </div>
        <table class="table">
          <tbody>
            <tr>
              <td class="doc-name" style="width: 130px">补贴名称</td>
              <td class="doc-description">
                <!-- <ul>
                                        <li id="butiename"></li>
                                    </ul> -->
                <span id="butiename">{{ data.name }}</span>
              </td>
            </tr>
            <tr>
              <td class="doc-name" style="width: 130px">发放单位</td>
              <td class="doc-description">
                <span id="fafangdanwei">{{ data.department }}</span>
              </td>
            </tr>
            <tr>
              <td class="doc-name" style="width: 130px">发放时间</td>
              <td class="doc-description">
                <span id="fafangshijian">{{ data.paymentTime }}</span>
              </td>
            </tr>
            <tr>
              <td class="doc-name" style="width: 130px">受益群体</td>
              <td class="doc-description">
                <span id="shouYiQunTi">{{ data.person }}</span>
              </td>
            </tr>
            <tr>
              <td class="doc-name" style="width: 130px">补贴内容</td>
              <td class="doc-description" v-html="data.content"></td>
            </tr>
            <tr>
              <td class="doc-name" style="width: 130px">发放形式</td>
              <td class="doc-description">
                <span id="fafangXingshi">{{ data.form }}</span>
              </td>
            </tr>
            <tr>
              <td class="doc-name" style="width: 130px">发放金额</td>
              <td class="doc-description">
                <span id="money">{{ data.money }}</span
                >元
              </td>
            </tr>
          </tbody>
        </table>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import AddOrUpdate from "./huinongbutie-add-or-update";
export default {
  data() {
    return {
      dialogVisible: false,
      dataForm: {
        key: ""
      },
      data: [],
      dataList: [],
      pageIndex: 1,
      pageSize: 10,
      totalPage: 0,
      dataListLoading: false,
      dataListSelections: [],
      addOrUpdateVisible: false
    };
  },
  components: {
    AddOrUpdate
  },
  activated() {
    this.getDataList();
  },
  methods: {
    // 获取数据列表
    getDataList() {
      this.dataListLoading = true;
      this.$http({
        url: this.$http.adornUrl("/huinong/huiNongSubsidy/list"),
        method: "get",
        params: this.$http.adornParams({
          page: this.pageIndex,
          limit: this.pageSize,
          key: this.dataForm.key
        })
      }).then(({ data }) => {
        if (data && data.code === 0) {
          this.dataList = data.page.list;
          this.totalPage = data.page.totalCount;
        } else {
          this.dataList = [];
          this.totalPage = 0;
        }
        this.dataListLoading = false;
      });
    },
    // 每页数
    sizeChangeHandle(val) {
      this.pageSize = val;
      this.pageIndex = 1;
      this.getDataList();
    },
    // 当前页
    currentChangeHandle(val) {
      this.pageIndex = val;
      this.getDataList();
    },
    // 多选
    selectionChangeHandle(val) {
      this.dataListSelections = val;
    },
    // 新增 / 修改
    addOrUpdateHandle(id) {
      this.addOrUpdateVisible = true;
      this.$nextTick(() => {
        this.$refs.addOrUpdate.init(id);
      });
    },
    checkHandle(id) {
      this.$nextTick(() => {
        this.dataListLoading = true;
        (this.dialogVisible = true),
          this.$http({
            url: this.$http.adornUrl(`//huinong/huiNongSubsidy/info/${id}`),
            method: "get",
            params: this.$http.adornParams()
          }).then(({ data }) => {
            if (data && data.code === 0) {
              this.data = data.huiNongSubsidy;
            }
          });
        this.dataListLoading = false;
      });
    },
    // 删除
    deleteHandle(id) {
      var ids = id
        ? [id]
        : this.dataListSelections.map(item => {
            return item.id;
          });
      this.$confirm(
        `确定对[id=${ids.join(",")}]进行[${id ? "删除" : "批量删除"}]操作?`,
        "提示",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }
      ).then(() => {
        this.$http({
          url: this.$http.adornUrl("/huinong/huiNongSubsidy/delete"),
          method: "post",
          data: this.$http.adornData(ids, false)
        }).then(({ data }) => {
          if (data && data.code === 0) {
            this.$message({
              message: "操作成功",
              type: "success",

              onClose: () => {
                this.getDataList();
              }
            });
          } else {
            this.$message.error(data.msg);
          }
        });
      });
    }
  }
};
</script>
<style scoped>
.head {
  background: url("../../assets/img/daohang.jpg") no-repeat;
  width: 100%;
}
.Article {
  width: 1200px;
  margin: 0 auto;
  background-color: rgba(241, 241, 241, 0.26);
}
.table {
  border-bottom: 1px solid #999;
  border-bottom-width: 1px;
  border-bottom-style: solid;
  border-bottom-color: #999;
  margin-bottom: 0;
  border-spacing: 0;
  margin-top: 20px;
}
.col-md-9 .box {
  background: 0;
}

.paperCut .box {
  margin-bottom: 10px;
}
.pagelujing {
  margin-top: 12px;
  height: 40px;
  border-bottom: 2px solid #ccc;
  position: relative;
}
.doc-name {
  font-weight: bold;
}
.table > tbody > tr > td {
  border-right: 1px solid #999;
  border-right-width: 1px;
  border-right-style: solid;
  border-right-color: #999;
}
.table > tbody > tr > td,
.table > tbody > tr > th,
.table > tfoot > tr > td,
.table > tfoot > tr > th,
.table > thead > tr > td,
.table > thead > tr > th {
  padding: 8px 30px;
  line-height: 1.42857143;
  border-top: 1px solid #999;
  border-left: 1px solid #999;
}

.button {
  background-color: #19678e;
  opacity: 0.9;
  width: 40px;
  height: 25px;
  color: white;
  padding-top: 6px;
}
.title {
  color: green;
  font-size: 25px;
  line-height: 100%;
  margin-right: 20px;
  margin-left: 40px;
  display: inline-block;
}
.text {
  color: black;
  font-size: 22px;
  width: 80%;
  margin-bottom: 30px;
  display: inline-block;
}
.text1 {
  margin-left: 120px;
  margin-top: -35px;
}
</style>
